package com.zfast.yugioh.controller;

import javax.annotation.Resource;

import com.zfast.forge.common.BaseResult;
import com.zfast.forge.common.Page;
import com.zfast.forge.valid.Create;
import io.swagger.annotations.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.github.pagehelper.PageInfo;

import com.zfast.yugioh.model.Test;
import com.zfast.yugioh.service.TestService;

import java.util.ArrayList;
import java.util.List;


/**
 * 测试表
 *
 * @author zgn
 * @email
 * @date 2022-06-01 15:51:47
 */
@RestController
@RequestMapping("api/test")
@Api(tags = {"testController"})
public class TestController{
    @Resource
    TestService testService;

    @PostMapping({"/list"})
    @ApiOperation(value = "测试表数据列表", httpMethod = "POST", notes = "获取测试表列表")
    public BaseResult<PageInfo<Test>> list(Test test, Integer num, Integer size) {
        BaseResult result=BaseResult.builder()
                .msg("获取测试表列表成功")
                .data(testService.pageList(test,num,size))
                .build();
        return result;
    }

    @PostMapping({"/listFx"})
    @ApiOperation(value = "泛型查询数据list", httpMethod = "POST", notes = "泛型查询数据list")
    public BaseResult<PageInfo<Test>> 泛型查询数据list(@RequestBody Page<Test> page) {
        BaseResult result=BaseResult.builder()
                .msg("获取测试表列表成功")
                .data(testService.pageList(page.getData(),page.getNum(),page.getSize()))
                .build();
        return result;
    }

    @GetMapping({"/get/{id}"})
    @ApiOperation(value = "测试表数据列表", httpMethod = "GET", notes = "获取单个测试表记录")
    public BaseResult<Test> get(@ApiParam(name = "id", value = "业务对象主键", required = true) @PathVariable Integer id) {
        /*BaseResult result=BaseResult.builder()
                .msg("查询测试表成功")
                .data(testService.get(id))
                .build();*/
        BaseResult<Test> result=new BaseResult<>();
        result.setMsg("查询测试表成功");
        result.setData(testService.get(id));
        return result;
    }

    @PostMapping({"add"})
    @ApiOperation(value = "新增测试表信息", httpMethod = "POST", notes = "保存测试表")
    public BaseResult<Integer> add(@RequestBody @Validated(Create.class) Test model) {
        BaseResult result=BaseResult.builder()
                .msg("添加测试表成功")
                .data(testService.insert(model))
                .build();
        return result;
    }

    @PostMapping({"update"})
    @ApiOperation(value = "更新指定id的 测试表 信息（更新全部信息）", httpMethod = "POST", notes = "更新指定id的 测试表 信息（更新全部信息）")
    public BaseResult<Integer> update(@RequestBody @ApiParam(name = "test", value = "测试表业务对象", required = true) Test model) {
        BaseResult result=BaseResult.builder()
                .msg("更新测试表成功")
                .data(testService.update(model))
                .build();
        return result;
    }

    @GetMapping({"remove/{id}"})
    @ApiOperation(value = "删除测试表记录", httpMethod = "GET", notes = "删除测试表记录")
    public BaseResult<Integer> remove(@ApiParam(name = "id", value = "业务主键", required = true) @PathVariable Integer id) {
        BaseResult result=BaseResult.builder()
                .msg("删除测试表成功")
                .data(testService.delete(id))
                .build();
        return result;
    }

    @GetMapping({"/swagger/{id}"})
    @ApiOperation(value = "测试表数据列表", httpMethod = "GET", notes = "获取单个测试表记录")
    public Page<List<Test>> 测试swagger(@ApiParam(name = "id", value = "业务对象主键", required = true) @PathVariable Integer id) {
        Page<List<Test>> result=new Page<>();
        Test test = testService.get(id);
        List<Test> list =new ArrayList<>();
        for (int i = 0; i <5; i++) {
            list.add(test);
        }
        result.setData(list);
        return result;
    }
}
